-- @owner: @zou_jialiang050
-- @date: 2022/02/24
-- @testpoint: 在更新src视图时使用触发器函数直接替换触发条件

--step1:建表;expect:成功
drop table if exists t_trigger_src_59 cascade;
create table t_trigger_src_59(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在更新src视图时使用触发器函数直接替换触发条件;expect:成功 id1值为100
create or replace view t_trigger_src_59_view1 as select * from t_trigger_src_59;
create or replace function insert_func()
returns trigger as $$
begin
update t_trigger_src_59 set id1=100;
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_59_view1;
create trigger insert_trigger_1
instead of update on t_trigger_src_59_view1
for each row
execute procedure insert_func();
/
insert into t_trigger_src_59 values(1,1,1),(2,2,2),(3,3,3);
select * from t_trigger_src_59 order by id1;
update t_trigger_src_59_view1 set id1=10;
select * from t_trigger_src_59 order by id1;
select * from t_trigger_src_59_view1 order by id1;

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger_1 on t_trigger_src_59_view1;
drop table if exists t_trigger_src_59 cascade;
drop view if exists t_trigger_src_59_view1;
drop function if exists insert_func;